package com.example.www.jiguvideo.console.controller;


import com.example.www.jiguvideo.module.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigInteger;

@RestController
public class VideoController {

    @Autowired
    private VideoService Service;

    @RequestMapping("/video/create")
    public String videoCreate(@RequestParam(name = "name") String name,
                              @RequestParam(name = "image") String image,
                              @RequestParam(name = "introduce") String introduce,
                              @RequestParam(name = "pictures") String pictures,
                              @RequestParam(name = "actor") String actor,
                              @RequestParam(name = "particular") String particular,
                              @RequestParam(name = "photo") String photo) {
        // 去除各个参数两边的空格
        name = name.trim();
        introduce = introduce.trim();
        actor = actor.trim();
        particular = particular.trim();

        int result = Service.createVideo(name,image, introduce, pictures, actor, particular, photo);
        return 1 == result ? "成功" : "失败" ;
        }


    @RequestMapping("/video/update")
    public String videoUpdate(@RequestParam(name = "videoId") BigInteger videoId,
                              @RequestParam(name = "name") String name,
                              @RequestParam(name = "image") String image,
                              @RequestParam(name = "introduce") String introduce,
                              @RequestParam(name = "pictures") String pictures,
                              @RequestParam(name = "actor") String actor,
                              @RequestParam(name = "particular") String particular,
                              @RequestParam(name = "photo") String photo) {
        // 去除各个参数两边的空格
        name = name.trim();
        introduce = introduce.trim();
        actor = actor.trim();
        particular = particular.trim();

        int result = Service.updateVideo(videoId,name, image, introduce, pictures, actor, particular, photo);
        return 1 == result ? "成功" : "失败" ;
    }

    @RequestMapping("/video/delete")
    public String videoDelete(@RequestParam(name = "videoId") BigInteger videoId){

        int  result = Service.deleteVideo(videoId);
        return 1 == result  ? "成功":"失败";
    }
}

